
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: 113
  Date: 2020/10/2
  Time: 10:34
  To change this taemplate use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  request.setCharacterEncoding("utf-8");
  String username = request.getParameter("username");
  String password = request.getParameter("password");

  Class.forName("com.mysql.jdbc.Driver");

  String url = "jdbc:mysql://localhost:3306/book";
  Connection connection = DriverManager.getConnection(url,"root","root");

  String sql = "select * from user where username=? and password=?";
  PreparedStatement ps = connection.prepareStatement(sql);


  ps.setString(1,username);
  ps.setString(2,password);
  ResultSet rs = ps.executeQuery();

  if (rs.next()){
    //response.sendRedirect("home.jsp");
 //out.print("登陆成功");
 session.setAttribute("username",username);
 out.print("登陆成功");
 response.sendRedirect("home.jsp");
  }else{
    //response.sendRedirect("login.jsp");
  out.print("登陆失败,3秒之后跳转登录页面...");
  response.setHeader("refresh","3;url=login.jsp");
  }
%>